<?php
include_once("adminBase.php");
include_once( _INC_PATH."catecae.php" );

class Recom extends AdminBase{
	private $type = 'sypl';
	private $s_type = 0;
	private $typeInfo = array('sypl'=>'推荐5个评论','qysy'=>'推荐5个企业图片');

	function recom()
	{
		if(isset($_REQUEST['type']) && $_REQUEST['type'] != ""){
			$this->type = $_REQUEST['type'];
		}
		if(isset($_REQUEST['s_type']) && $_REQUEST['s_type'] != ""){
			$this->s_type = $_REQUEST['s_type'];
		}
		parent::adminbase();
	}

	function index()
	{	
		global $cateSubCae;
		$type = $this->type;
		$s_type = $this->s_type;
		$sql = "select * from tbl_recom where type='$type' and del_flg='0' ".(empty($s_type)?'':' and s_type=\''.$s_type.'\'');
		$this->db->setQuery($sql);
		$data = $this->db->loadList();
		$this->smarty->assign("rows",$data);
		$this->smarty->assign("type",$type);
		$this->smarty->assign("s_type",$s_type);
		$this->smarty->assign("cateSub",$cateSubCae);
		$this->smarty->assign("info",$this->typeInfo[$type]);
		adminDisplay("admin_recom.tpl");
	}
	function save()
	{
		$recom_ids = $_POST['recom_id'];
		foreach($recom_ids as $key=>$value)
		{
			$temprow = array();
			if(intval($value) == 0 && empty($_POST['id'][$key])){
				continue;
			}elseif(intval($value) == 0 && !empty($_POST['id'][$key])){
				$temprow['del_flg'] = '1';
				$id = intval($_POST['id'][$key]);
				$this->db->update($temprow,"tbl_recom","where id='".$id."'");
				$this->managerLog($id, 'tbl_recom');
				continue;
			}
			$temprow['type'] = $this->type;
			$temprow['s_type'] = $this->s_type;
			$temprow['recom_id'] = intval($value);
			$temprow['title'] = trim($_POST['title'][$key]);
			$temprow['content'] = trim($_POST['content'][$key]);
			if(isset($_POST['id'][$key]) && $_POST['id'][$key] > 0){
				$id = intval($_POST['id'][$key]);
				$this->db->update($temprow,"tbl_recom","where id='".$id."'");
				$this->managerLog($id, 'tbl_recom');
			}else{
				if($id = $this->db->insert($temprow,"tbl_recom")){
					$this->managerLog($id, 'tbl_recom');
				}
			}
		}
		$_SESSION['sysMsg'] = '设置成功';
		$this->index();
	}
}

$recom = new Recom();